﻿using IniReadWrite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisionRoc.Tool;

namespace VisionRoc.Core
{
    public class ImageSavePath
    {
        string m_Path;
        public ImageSavePath(string _Path)
        {
            //判断文件路径是否存在
            if (!Directory.Exists(_Path))
            {
                Directory.CreateDirectory(_Path);
            }
            m_Path = _Path + "\\Path.ini";
            if (File.Exists(m_Path))
            {
                ReadImageSavePath();
            }
            else
            {
                CameraPath = "NULL";
            }
        }

        /// <summary>
        /// 相机1 图像保存路径
        /// </summary>
        public string CameraPath;

        /// <summary>
        /// 数据表格路径
        /// </summary>
        public string DataPath { get; set; }

        /// <summary>
        /// 数据表格显示数量
        /// </summary>
        public int DataNum { get; set; }

        /// <summary>
        /// Log日志路径
        /// </summary>
        public string LogPath;


        /// <summary>
        /// 保存图像路径参数
        /// </summary>
        public void WriteImageSavePath()
        {
            try
            {
                IniAPI.INIWriteValue(m_Path, "Path", "Camera1Path", CameraPath.ToString());
                IniAPI.INIWriteValue(m_Path, "Path", "DataPath", DataPath.ToString());
                IniAPI.INIWriteValue(m_Path, "Path", "DataNum", DataNum.ToString());
                IniAPI.INIWriteValue(m_Path, "Path", "LogPath", LogPath.ToString());
            }
            catch (Exception ex)
            {
                Global.AddLogInfoEvent(LogLevel.Error, "保存路径信息错误");
                TxtAPI.WriteLogTxt($"保存路径信息错误:{ex.ToString()}");
            }
        }

        /// <summary>
        /// 读取图像路径参数
        /// </summary>
        public void ReadImageSavePath()
        {
            try
            {
                CameraPath = IniAPI.INIGetStringValue(m_Path, "Path", "Camera1Path", "0");
                DataPath = IniAPI.INIGetStringValue(m_Path, "Path", "DataPath", "0");
                DataNum = Convert.ToInt32(IniAPI.INIGetStringValue(m_Path, "Path", "DataNum", "0"));
                LogPath = IniAPI.INIGetStringValue(m_Path, "Path", "LogPath", "0");
            }
            catch(Exception ex)
            {
                Global.AddLogInfoEvent(LogLevel.Error, "读取路径信息错误");
                TxtAPI.WriteLogTxt($"读取路径信息错误:{ex.ToString()}");
            }
        }


    }
}
